#include "soldier.h"

soldier::soldier(std::string name)
{
    this->name_ = name;
    this->ptr_gun_ = nullptr;
}

soldier::~soldier()
{
    if (this->ptr_gun_ != nullptr)
    {
        delete this->ptr_gun_;
        return;
    }
}

void soldier::addGun(std::string gun_name)
{
    if (this->ptr_gun_ != nullptr)
    {
        std::cout << "I have already one gun. no need to add gun." << std::endl;
        return;
    }
    this->ptr_gun_ = new gun(gun_name);
    std::cout << "Add gun successfully!" << std::endl;
    return;
}

void soldier::addBullet(int num)
{
    this->ptr_gun_->addBullet(num);
}

bool soldier::fire()
{
    if (this->ptr_gun_ == nullptr)
    {
        std::cout << "I have no gun. Fire failed." << std::endl;
        return false;
    }
    ptr_gun_->shoot();
    return true;
}